<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- {{firstName+" "+lastName}} -->
        {{fullName}}
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                firstName: "Dell",
                lastName: "Lee",
                fullName: "Dell Lee"
            },
            watch: {
                // 侦听器监听firstName，当firstName发生改变时，就对fullName重新赋值
                firstName: function () {
                    this.fullName = this.firstName + this.lastName;
                },
                // 侦听器监听lastName，当lastName发生改变时，就对fullName重新赋值
                lastName: function () {
                    this.fullName = this.firstName + this.lastName;
                }
            },
        })
    </script>
</body>

</html>